package cn.itsource.wechat.controller;

import cn.itsource.basic.util.AjaxResult;
import cn.itsource.wechat.pojo.dto.BinderDto;
import cn.itsource.wechat.pojo.dto.WechatProperties;
import cn.itsource.wechat.service.IWeChatService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller //不会返回json格式  如有方法需要返回json格式，就单独给方法配置@ResponseBody
@RequestMapping("/wechat")
@Slf4j
public class WeChatController {

    @Autowired
    private WechatProperties wechatProperties;


    @Autowired
    private IWeChatService weChatService;

    /**
     * 测试通过类获取yml的值
     */
    @RequestMapping("/test")
    @ResponseBody
    public void test(){

        log.info("对象，{},app,{}",wechatProperties,wechatProperties.getAppId());
    }
    /**
     * 重定向扫码页面
     * "redirect:/haha.html" :重定向
     */
    @GetMapping("/tologin")
    //@ResponseBody  //这个不能要
    public String tologin(){

        return weChatService.tologin();
    }
    /**
     *  获取code
     */
    @GetMapping("/callback")
    //@ResponseBody  //这个不能要
    public String callback(String code){
        String callback = weChatService.callback(code);

        System.out.println("callback= "+ callback);
        return callback;
    }
    /**
     *  获取code
     */
    @PostMapping("/binder")
    @ResponseBody  //这个不能要
    public AjaxResult binder(@RequestBody BinderDto binderDto){
        return weChatService.binder(binderDto);

    }

    @GetMapping("/callback2")
    //@ResponseBody  //这个不能要
    public String callback2(){

        return "redirect:http://localhost:8081/index.html";
    }
}
